<?php
/**
 * 简单评论插件
 * @author ghoot
 */

namespace addons\Comment;
use app\common\controller\Addons;

class Action extends Addons{

    public function post(){
        $the_user = session('user_auth');
        $user_data=[];
        if($the_user){
            $user_data['uname'] = $the_user['username'];
            $user_data['uid'] = $the_user['uid'];
        }else{
            $user_data['uid'] = 0;
            $uname = input('post.uname');
            if(empty($uname)){
                $this->error('匿名用户必须填写一个称呼！');
                exit;
            }
            $user_data['uname'] = $uname;
        }
        $user_data['aim_table'] = input('post.atable');
        $user_data['aim_id'] = input('post.aid');
        $user_data['ctime'] = time();
        $user_data['content'] = input('post.content');
        $config=$this->getConfig();
        $user_data['is_audit'] = $config['audit'] ? 1 : 0;

        $insert = db('comment')->insert($user_data);
        if($insert){
            $this->success('评论发表成功！');
        } else {
            $this->error('评论发表失败！');
        }


    }
}